/*
 * 通用方法 相关操作
 *
 * @Author:    lishan
 * @Date:      2024-08-22 9:51
 * @Copyright  
 */
export const downloadFile(data, fileName) {
  return new Promise((resolve, reject) => {
    const json = JSON.stringify(data, null, 2);
    const blob = new Blob([json], { type: 'application/json' });
    const url = URL.createObjectURL(blob);
 
    const a = document.createElement('a');
    a.href = url;
    a.download = `${fileName}.json`;
    a.click();
 
    resolve('File has been exported successfully');
    
  });
};

export const  downloadFiles(content, fileName, mimeType) {
  // 创建一个Blob实例，其中包含要下载的内容
  const blob = new Blob([content], { type: mimeType });
 
  // 创建一个指向Blob的URL
  const url = URL.createObjectURL(blob);
 
  // 创建一个a元素，用于触发下载
  const downloadLink = document.createElement('a');
  downloadLink.href = url;
  downloadLink.download = fileName; // 指定下载文件名
 
  // 将a元素添加到文档中，并模拟点击它
  document.body.appendChild(downloadLink);
  downloadLink.click();
 
  // 清理并移除元素和Blob URL
  document.body.removeChild(downloadLink);
  URL.revokeObjectURL(url);
}